package com.atguigu.flink.sql;

import com.atguigu.flink.function.WaterSensorMapFunction;
import com.atguigu.flink.pojo.WaterSensor;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * Created by Smexy on 2022/12/21
 *
 *   读
 *       tableEnv.sqlQuery( select sql)
 *
 *   写和 DDL
 *       tableEnv.executeSql(insert sql)
 */
public class Demo3_ReadFile
{
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

      /*
            创建目标表,和外部的文件系统映射

       */
      String  createTableSQL = " CREATE TABLE t1( id string, ts bigint , vc int  ) " +
          "                       WITH (  " +
          "                         'connector' = 'filesystem',  " +
          "                         'path' = 'data/t1',   " +
          "                         'format' = 'csv'    " +
          "                            )      ";


      //建表(连接外部文件系统)
      tableEnv.executeSql(createTableSQL);

      tableEnv.sqlQuery("select * from t1 where id = 's1' ")
              .execute()
              .print();
    }
}
